package cn.edu.scau.Servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class Check_Servlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		req.setCharacterEncoding("utf-8");

		resp.setCharacterEncoding("utf-8");

		resp.setContentType("text/html; charset=utf-8");

		String check_code = req.getParameter("check_code").toUpperCase();

		HttpSession session = req.getSession();

		PrintWriter pw = resp.getWriter();

		String rand = ((String) session.getAttribute("rand")).toUpperCase();

		System.out.println(check_code);

		System.out.println(rand);

		if (check_code.equals(rand)) {

			pw.write("校验成功");

		} else {
			resp.sendRedirect("login.jsp");
		}

		pw.close();
	}
}
